#ifndef RAFT_TIMER
#define RAFT_TIMER

#include "ffz/bit-ops.h"


//candidate timer reset seconds 15 + (0~15)
#define CANDIDATE_RANDOM_SECONDS 15
#define LEADER_BEATS_SECONDS 10
#define CANDIDATE_PERIODIC_REQUEST 3

#define COUNTER_INDEX_CANDIDATE 0
#define COUNTER_INDEX_LEADER_BEATS 1
#define COUNTER_INDEX_CANDIDATE_PERIODIC 2

/**get a random candidate time with CANDIDATE_RANDOM_SECONDS
 * */
uint16_t getResetCandidateTime();
/**set the clock unit as 'val'
 * after this operation
 * each time when you call refreshCandidateClock()
 * the counter will increase the unit value as the setting 'val'
 * */
void initCandidateClockUnit(uint16_t val);
/**increase the counter with value 'val', 
 * which is set in the initCandidateClockUnit(unsigned long val);
 * */
uint16_t refreshCandidateClock(uint8_t index);
/**
 * set the trigger clock
 * */
uint16_t getTriggerClock(uint8_t index);
/**reset the clock count 
 * if the type == 1, it will reset the trigger time
 * while type == others, it will not reset the trigger time
 * */
void resetClockCount(uint8_t type);
#endif